#ifndef NETWORK_MANAGER_HH
# define NETWORK_MANAGER_HH

# include "../request/request-creator.hh"
# include "network-error-handler.hh"

# include <boost/shared_ptr.hpp>

# include <boost/asio.hpp>
# include <boost/array.hpp>
# include <boost/shared_ptr.hpp>

using boost::asio::ip::tcp;

class NetworkManager
{
public:
  NetworkManager (tcp::socket* socket, RequestCreator* rc, NetworkErrorHandler* eh);
  ~NetworkManager ();

  boost::shared_ptr<Request> read ();
  void send (RequestType rt, const std::string& data);

  std::string raw_read ();
  void raw_send (const std::string& data);

  //force the sending of a raw_send buffer (must be done when finish sending)
  void flush ();

  tcp::socket* s () const { return s_; }
  RequestCreator* rc () const { return rc_; }

  NetworkErrorHandler* eh () const { return eh_; }

  static const unsigned buf_size = 1000;

protected:
  tcp::socket* s_;
  RequestCreator* rc_;
  NetworkErrorHandler* eh_;

  char* receive_buf_;
  char* send_buf_;
  unsigned send_size_;
  char* charbuf_;
};

#endif /// !NETWORK_MANAGER_HH
